﻿
-- =============================================
-- Author:		Dorin Popa
-- Create date: 28.12.2009
-- Description:	Inchide luna la Amix cu generarea amortizarii pe luna curenta
-- =============================================
CREATE PROCEDURE [dbo].[resuma_GenereazaListaDepartamentePA] 
	-- Add the parameters for the stored procedure here
	@idPersoana int,
	@DataCurenta datetime, 
	@CodUnitate smallint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    SELECT DISTINCT b.Nume,b.IDDepartament FROM resuma_PersonalAngajat a JOIN Departamente b ON a.IDDepartament=b.IDDepartament
	WHERE DeLaData<=@DataCurenta AND (PanaLaData IS NULL OR YEAR(@DataCurenta)*100+MONTH(@DataCurenta)<=YEAR(PanaLaData)*100+MONTH(PanaLaData))
	AND (DataPlecarii IS NULL OR YEAR(@DataCurenta)*100+MONTH(@DataCurenta)<=YEAR(DataPlecarii)*100+MONTH(DataPlecarii)) AND (a.CodUnitate=@CodUnitate)
	AND (IdPersoana = @idPersoana)
END